class MyThread2 implements Runnable{

    @Override
    public void run() {
        while(true){
            System.out.println("hello thread\n");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
public class ThreadDemo {
    public static void main(String[] args) throws InterruptedException {

        /*写法1
        Runnable runnable = new MyThread2();
        Thread thread = new Thread(runnable);
        */

        //写法2
        Thread thread = new Thread(new MyThread2());//注意，Runnable本身只是一个可执行的逻辑，真正要创建出线程，还是要靠Thread本体

        thread.start();
        while(true){
            System.out.println("hello main\n");
            Thread.sleep(1000);
        }
    }
}

